<?php

/**
 * Created by PhpStorm.
 * User: HuangLuSen
 * Date: 2017/5/11
 * Time: 10:42
 */
namespace app\common\message\type;
use app\common\message\SendType;
use Flc\Alidayu\Client;
use Flc\Alidayu\App;
use Flc\Alidayu\Requests\AlibabaAliqinFcSmsNumSend;
use Flc\Alidayu\Requests\IRequest;

class SmsType extends SendType
{
   protected $options = [
//           'app_key'    => '23817577',
//           'app_secret' => '6a08ff71fc994d130e550be1990e4640',
           'app_key'    => '',
           'app_secret' => '',
           'freesignname' 	=> '儿童天堂玛瑞莎',//短信签名
        ];
    public $alidayureq;
    public $alidayuclient;
    public function __construct()
    {
        $config = config('we.alidayu');
        if(!empty($config)) $this->options=array_merge($this->options,$config);
        $this->alidayuclient = new Client(new App($this->options));
        $this->alidayureq    = new AlibabaAliqinFcSmsNumSend;
    }

    /**
     * 发送数据到队列
     * @param $data
     * @return mixed
     */
    public function push_to_queue($data)
    {
        // TODO: Implement push_to_queue() method.
    }

    /**
     * 发送数据到客户
     * @param $data ['phone'=>'xxx','param'=>['xx'=>'xxx'],'tempcode'=>'xxx','freesignname'=>'签名']
     * @return mixed
     */
    public function send_to_any(array $data)
    {
        $config = $this->options;
        is_array($data['phone'])?$phone = join(',',$data['phone']):$phone=$data['phone'];
        $this->alidayureq->setRecNum($phone)
            ->setSmsParam($data['param'])
            ->setSmsFreeSignName(!empty($data['freesignname'])?$data['freesignname']:$config['freesignname'])
            ->setSmsTemplateCode($data['tempcode']);
        return $this->alidayuclient->execute( $this->alidayureq);
    }
}